package com.security.exception;

import com.security.util.ServiceResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ExceptionHandlerAdvice {
    private static final Logger logger = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);

    @ExceptionHandler(BusinessException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public @ResponseBody
    ServiceResponse<String> businessException(Exception ex) {
        logger.error(ex.getMessage(),ex);
        System.out.println(1/0);
        return ServiceResponse.failure("500",ex.getMessage());
    }
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public @ResponseBody
    ServiceResponse<String> lastDefence(Exception ex) {
        logger.error(ex.getMessage(),ex);
        System.out.println(1/0);
        return ServiceResponse.failure("500","系统繁忙！");
    }
}
